package com.lcw.view.jpush;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

import com.lcw.view.MainActivity;
import com.lcw.view.R;


public class JPushService extends IntentService {

    private NotificationManager notificationManager;
    private Notification notification;
    private RemoteViews remoteViews;

    public JPushService() {
        super("JPushService");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        initNotify();
    }

    private void initNotify(){
        Notification notification = new NotificationCompat.Builder(this)

                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))

                .setSmallIcon(R.mipmap.ic_launcher)
               /* *//**//**通知首次出现在通知栏，带上升动画效果的**//**//**/
                .setTicker("通知来了")
                //**设置通知的标题**//*
                .setContentTitle("这是一个通知的标题")
                //**设置通知的内容**//*
                .setContentText("这是一个通知的内容这是一个通知的内容")
                //**通知产生的时间，会在通知信息里显示**//*
                .setWhen(System.currentTimeMillis())
                //**设置该通知优先级**//*
                .setPriority(Notification.PRIORITY_DEFAULT)
                //**设置这个标志当用户单击面板就可以让通知将自动取消**//*
                .setAutoCancel(true)
                //**设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)**//*
//                .setOngoing(false)
                //**向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置，使用defaults属性，可以组合：**/
                .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
                .setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT))
                .build();
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);


        notificationManager.notify(0, notification);
//        notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        Intent intent=new Intent(this,this.getClass());
//        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
//        PendingIntent pendingIntent=PendingIntent.getActivity(this,
//                R.string.app_name, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//        notification=new Notification();
//        notification.icon=R.mipmap.logo;
//        notification.flags=Notification.FLAG_ONLY_ALERT_ONCE;
//        notification.defaults=Notification.DEFAULT_SOUND;
//        remoteViews=new RemoteViews(getPackageName(), R.layout.item_notification);
////        remoteViews.setTextViewText(R.id.tv_notification_name, "英语现在学正在下载");
////        remoteViews.setImageViewResource(R.id.iv_download, R.mipmap.logo);
////        remoteViews.setProgressBar(R.id.pb_download, 100, 0, false);
//        notification.contentView=remoteViews;
//        notification.contentIntent=pendingIntent;
//        notificationManager.notify(0, notification);
    }
}